package com.haixiaoke.framework.aspectj;

import com.haixiaoke.handle.DictHandle;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * 字典翻译切面
 *
 * @author zhiping
 */
@Aspect
@Component
public class DictAspect {

    @Pointcut("@annotation(com.haixiaoke.common.annotation.DictCovert)")
    public void dictCovert() {
    }

    @Around("dictCovert()")
    public Object process(ProceedingJoinPoint joinPoint) throws Throwable {
        // 1. 执行原方法
        Object proceed = joinPoint.proceed();
        // 2. 拿到原方法的原返回值 调用parseResult进行字典转换
        Object result = DictHandle.parseResult(proceed);
        DictHandle.clearCache();
        return result;
    }

}
